var Poker = require('../Poker/Poker');
var NN = require('../Poker/NN');

var PokerPlayer = require('../Poker/player').PokerPlayer;

var Const = require('./const');

exports.JCNNPlayer = PokerPlayer.extend({
    _robDealer: -1,         // 抢庄状态，-1/0/1 未选择/不抢/抢庄
    _selectedCards: [],     // 选择的三张牌
    _ante: 0,
    _playCards: false,
    _calcKanCards: null,
    _calBoomNiuCards: null,
    _calShunNiuCards: null,
    _lookCards: false,
    _giveUp: false,
    _ghostResultArray: [],
    _lastPatternScore: 0,
    _compareIndexArr: [],
    _winNum: 0,
    _failNum: 0,
    _niuNum: 0,
    _noNiuNum: 0,

    init: function(uid, msg) {
        this._super(uid, msg);

        this._robDealer = -1;
        this._selectedCards = [];
        this._ante = 0;
        this._playCards = false;
        this._stat.roundPattern = Const.Pattern.NONE;
        this._lastPatternScore = 0;
        this._calcKanCards = [];
        this._calBoomNiuCards = [];
        this._calShunNiuCards = [];
        this._ghostResultArray = [];
        this._compareIndexArr = [];
        this._lookCards = false;
        this._giveUp = false;
        this._tuiZu = [];
        this._winNum = 0;
        this._failNum = 0;
        this._niuNum = 0;
        this._noNiuNum = 0;
    },

    setRotDealer: function(value) {
        this._robDealer = value;
    },

    getRobDealer: function() {
        return this._robDealer;
    },

    setAnte: function(value) {
        this._ante = value;

        var room = this.getRoom();
        room.broadcast("onPlayerAnteChange", {
            playerIndex: this.getIndex(),
            ante: this._ante
        });
    },

    getAnte: function() {
        return this._ante;
    },

    setRoundPattern: function(pattern, score) {
        this._stat.roundPattern = pattern;
        this._stat.roundPatternScore = score || 0;
    },

    getRoundPattern: function() {
        return this._stat.roundPattern;
    },

    setLastPatternScore: function (score) {
        // 对应不同的规则推注的规则也不相同
        this._lastPatternScore = score;
    },

    getLastPatternScore: function() {
        return this._lastPatternScore;
    },

    /**
     * 添加当前结算数据
     * @param num
     */
    addRoundInfoNum: function (num) {
        if (num > 0) {
            this._winNum += 1;
        }else {
            this._failNum += 1;
        }

        if (this.getRoundPattern() == Const.Pattern.wuNiu) {
            this._noNiuNum += 1;
        }else {
            this._niuNum += 1;
        }
    },

    getRoundPatternScore : function () {
        return this._stat.roundPatternScore;
    },

    getGhostPlaceArray: function () {
        return this._ghostResultArray;
    },

    setSelectedCards: function(cardsArr) {
        if (!cardsArr || cardsArr.length == 0) {
            this._selectedCards = [];
            return true;
        }

        var cards = Poker.buildFromArray(cardsArr);
        var allExist = true;
        var allPoint = 0;

        ExObject.eachKeyNum(cards, function(card, num) {
            if (!card) {
                allExist = false;
            }

            if (this._handCards.getCardNum(card) < num) {
                allExist = false;
            }

            allPoint += NN.getPoint(card) * num;
        }.bind(this));

        if (!allExist) {
            return false;
        }

        if (allPoint % NN.BASE != 0) {
            return false;
        }

        this._selectedCards = [];
        cardsArr.forEach(function(card) {
            this._selectedCards.push(card);
        }.bind(this));

        return true;
    },

    isSelectedCards: function() {
        return (this._selectedCards) ? true : false;
    },

    getSelectedCards : function () {
        return this._selectedCards;
    },

    setInitScore: function (score) {
        this._stat.score = score;
    },

    getBoomCards: function () {
        return this._calBoomNiuCards;
    },

    getKanShunCards: function () {
        return this._calcKanCards || this._calShunNiuCards;
    },

    setTuiZuResult : function (tuiZuResult) {
        this._tuiZu = tuiZuResult;
    },

    addCompareResult: function (index) {
        this._compareIndexArr.push (index);
    },

    hasCompare: function (index) {
        if (this._compareIndexArr.indexOf (index) != -1) {
            return true;
        }

        return false;
    },

    /**
     * 获取玩家当前的鬼牌数量
     * @returns []
     */
    getGhostArray: function () {

        // 获取玩家牌中是否有鬼牌
        var handcards = clone (this.getHandCards().getInitCards());
        var ghostCount = [];

        handcards.forEach ( function(key) {

            if (key == Poker.SpecPoint.JOKER_B
                || key == Poker.SpecPoint.JOKER_S) {
                ghostCount.push (key);
            }
        });

        return ghostCount;
    },

    /**
     * 是否是相同的花色
     * @returns {boolean}
     */
    isSameColor: function () {

        var handcards = [];
        var isSame = true;

        // 获取没有鬼牌的牌
        this.getHandCards().getInitCards().forEach (function (card) {

            if (card != Poker.SpecPoint.JOKER_B
                && card != Poker.SpecPoint.JOKER_S) {
                handcards.push (card);
            }
        });

        for (var index = 0; index < handcards.length - 1; ++index) {
            console.log ("获取当前的位置: " + index);

            var color1 = Poker.getColor (handcards[index]);
            var color2 = Poker.getColor (handcards[index + 1]);
            if (color1 != color2) {
                console.log ("第一个的花色: " + color1);
                console.log ("第二个的花色: " + color2);
                isSame = false;
                break;
            }
        }

        return isSame;
    },

    /**
     * 获取总的牌的值
     * @returns {number}
     */
    getSumCard : function () {

        var sum = 0;
        var handCards = this.getHandCards().getInitCards();

        for (var index = 0; index < handCards.length; ++index) {

            if (handCards[index] == Poker.SpecPoint.JOKER_B
                ||  handCards[index] == Poker.SpecPoint.JOKER_S) {
                continue;
            }

            sum += NN.getPoint(handCards[index]);
        }

        return sum;
    },

    getColorNum : function () {

        var handCards = this.getHandCards().getInitCards();
        var colorNum = 0;

        for (var index = 0 ; index < handCards.length; ++index) {
            if (Poker.getPoint(handCards[index]) > 10) {
                colorNum += 1;
            }
        }

        return colorNum;
    },

    /**
     * 获取最大牌型
     * @param patternArray
     * @param patternResult
     */
    getMaxPattern: function (patternArray, patternResult) {

        var maxResult;
        for (var index = 0; index < patternArray.length; ++index) {

            var firPattern = patternResult[patternArray[index]];
            console.log ("获取替换的牌组: " + firPattern);
            var firArray = {};
            if (firPattern) {
                firArray = this._getMaxCard (firPattern);
            }

            var firResult = {Pattern: patternArray[index], maxArray: firArray};

            if (this.compareEachResult (firResult, maxResult)) {
                console.log ("获取替换牌组: " + firPattern);
                maxResult = {Pattern: firResult.Pattern, maxArray: firResult.maxArray, ghostResult: firPattern};
            }
        }

        // 设置当前的替换鬼牌组
        this._ghostResultArray = maxResult.ghostResult;

        if (maxResult.Pattern > Const.Pattern.niuniu) {
            this._selectedCards = [];
        }

        return maxResult;
    },

    /**
     * 获取正常的顺子数组
     * @param handcards
     * @returns {Array}
     */
    getShunZiArray: function (handcards) {
        var arrays = [];

        for (var index = 0; index < handcards.length - 2; ++index) {
            console.log ("获取 " + index + " 位置的值：" + handcards[index].point);
            console.log ("获取 " + (index + 1) + " 位置的值：" + handcards[index + 1].point);
            console.log ("获取 " + (index + 2) + " 位置的值：" + handcards[index + 2].point);

            if (handcards[index].point - handcards[index + 1].point == -1) {
                if (handcards[index + 1].point - handcards[index + 2].point == -1) {
                    console.log ("获取顺子");
                    var array = [handcards[index].card, handcards[index + 1].card, handcards[index + 2].card];
                    arrays.push (array);
                }
            }
        }

        // 特殊情况判断QKA
        if (handcards[0].point == 1) {
            var existQ = false;
            var qIndex = -1;
            var existK = false;
            var kIndex = -1;

            // 如果剩余的牌中存在Q和K的话, 则该牌型可达成
            for (var index = 0; index < handcards.length; ++index) {
                if (handcards[index].point == 12) {
                    existQ = true;
                    qIndex = index;
                }else if (handcards[index].point == 13) {
                    existK = true;
                    kIndex = index;
                }

                if (existQ && existK) {
                    var array = [handcards[0].card, handcards[qIndex].card, handcards[kIndex].card];
                    arrays.push (array);
                    break;
                }
            }
        }

        return arrays;
    },

    /**
     * 针对于一张鬼牌情况
     * @param handcards
     * @returns {Array}
     */
    getShunZiOneGhost: function (handcards) {
        var arrays = [];

        for (var index = 0; index < handcards.length - 1; ++index) {
            var array = {};
            var temp1 = handcards[index].point;
            var temp2 = handcards[index + 1].point;

            if (temp1 - temp2 == -1) {
                if (temp2 + 1 > 13) {
                    array = {way: "lSide", left1: temp1 - 1, card1: handcards[index].card, card2: handcards[index + 1].card};
                }else {
                    array = {way: "rSide", left1: temp2 + 1, card1: handcards[index].card, card2: handcards[index + 1].card};
                }
                arrays.push (array);
            }else if (handcards[index].point - handcards[index + 1].point == -2) {
                var left1 = temp1 + 1;
                array = {way: "inSide", left1: left1, card1: handcards[index].card, card2: handcards[index + 1].card};
                arrays.push (array);
            }
        }

        return arrays;
    },

    /**
     * 获取两个癞子的顺子
     * @param handcards
     * @returns {Array}
     */
    getShunZiTwoGhost: function (handcards) {

        var arrays = [];
        handcards.forEach (function (card) {

            // 默认往右, 然后就是中间， 没有全是左边的情况(和坎斗重复了)
            var point = card.point;
            // 特殊情况 需要找QKA
            if (point == 1) {
                var array = {way: "side", card1: card.card, left1: 12, left2: 13};
                arrays.push (array);
            }else {

                var num = 13 - point;
                if (num == 1) {
                    var array = {way: "inSide", card1: card.card, left1: point - 1, left2: point + 1};
                    arrays.push (array);
                }else if (num >= 2) {
                    var array = {way: "side", card1: card.card, left1: point + 1, left2: point + 2};
                    arrays.push (array);
                }
            }
        });

        return arrays;
    },

    /**
     * 获取两个鬼牌中的最大顺子
     * @param arrays
     * @returns {*}
     */
    getMaxArrayTwoGhost: function (arrays) {
        var maxIndex = 0;
        var maxScore = 0;

        for (var index = 0; index < arrays.length; ++index) {

            var array = arrays[index];
            // 获取每一个队列的最大
            var arrayMax = array.left2;

            if (arrayMax > maxScore) {
                maxIndex = index;
                maxScore = arrayMax;
            }
        }

        return arrays[maxIndex];
    },

    /**
     * 获取单个鬼牌中的最大
     * @param arrays
     * @returns {*}
     */
    getMaxArrayOneGhost: function (arrays) {

        var maxIndex = 0;
        var maxScore = 0;

        for (var index = 0; index < arrays.length; ++index) {

            var array = arrays[index];
            var arrayMax = 0;

            // 获取每一个队列的最大
            if (array.way == "lSide") {
                arrayMax = array.card2;
            }else if (array.way == "rSide") {
                arrayMax = array.left1;
            }else if (array.way == "inSide") {
                arrayMax = Poker.getPoint(array.card2);
            }

            if (arrayMax > maxScore) {
                maxIndex = index;
                maxScore = arrayMax;
            }
        }

        return arrays[maxIndex];
    },

    /**
     * 根据需要比较的鬼牌来计算最大的牌型
     * @param arrays
     * @returns {*}
     */
    getMaxArray: function (arrays) {

        var maxScore = 0;
        var maxIndex = 0;

        // 只需要比较最后一个值即可
        for (var index = 0; index < arrays.length; ++index){
            var point = Poker.getPoint (arrays[index][2]);
            if (point > maxScore) {
                maxIndex = index;
                maxScore = point;
            }
        }

        return arrays[maxIndex];
    },

    /******************************************************************
     * 重载的接口
     ******************************************************************/

    getInfo: function() {
        var info = this._super();
        info.remainScore = this._stat.remainScore;
        info.score = this._stat.score;
        return info;
    },

    getReconnectInfo: function(isSelf) {
        var info = this._super(isSelf);

        info.robDealer = this._robDealer;
        info.ante = this._ante;
        info.score = this.getScore();

        if (isSelf) {
            info.tuiZu = this._tuiZu;
            info.initCards = this.getHandCards().getInitCards();
        }

        if (isSelf || this._playCards) {
            info.handCards = this.getHandCards().getInitCards();
            info.selectCards = this._selectedCards;
            info.roundPattern = this.getRoundPattern();
            info.roundPatternScore = this.getRoundPatternScore();
            info.length = this.getHandCards().getCardNum();
        }

        info.playCards = this._playCards;
        return info;
    },

    getInitHandCardNeedNum: function() {
        return 5;
    },

    //getInitHandCardPreCards: function() {
    //    var preCards = [];
    //    if(this.getIndex() == 1){
    //        preCards.push(105);
    //        preCards.push(205);
    //        preCards.push(305);
    //    }else if(this.getIndex() == 2){
    //        preCards.push(210);
    //        preCards.push(310);
    //        preCards.push(110);
    //    }
    //    return preCards;
    //},

    getSettlementInfo: function() {
        var info = this._super();

        info.handCards = this.getHandCards().getInitCards();
        info.selectCards = this._selectedCards;
        info.winNum = this._winNum;             // 胜利次数
        info.failNum = this._failNum;           // 失败次数
        info.niuNum = this._niuNum;             // 有牛次数
        info.noNiuNum = this._noNiuNum;         // 无牛次数

        return info;
    },

    /**
     * 检查牛牌型
     * @param ghostArray
     * @param niuResult
     * @returns {*}
     */
    checkNiu: function (ghostArray, niuResult) {

        var pattern;

        // 首先获取除了鬼牌之外的总数
        var niuScore = this.checkFiveNiu();
        if (niuScore != null) {
            var result = [];
            var sumValue = this.getSumCard();
            var score = sumValue - niuScore;
            var value = score % NN.BASE;

            if (ghostArray.length >= 1) {
                pattern = Const.Pattern.niuniu;

                if (value == 0) {
                    ghostArray.forEach (function (ghost){
                        result.push ({card: ghost, value: Poker.getValue (2, 13)});
                    });
                }else {
                    if (ghostArray.length == 1) {
                        result.push ({card: ghostArray[0], value: Poker.getValue (2, (10 - value))});
                    }else {
                        ghostArray.forEach (function (ghost){
                            result.push ({card: ghost, value: Poker.getValue (2, 13)});
                        });
                    }
                }
            } else {
                if (value == 0) {
                    pattern = Const.Pattern.niuniu;
                }else {
                    pattern = Const.Pattern.wuNiu + value;
                }
            }    
            
            niuResult[pattern] = result;
            return pattern;
        }else if (ghostArray.length >= 1) {
            // 计算两张牌的牌值
            pattern = this.checkEachValue (ghostArray, niuResult);
        }

        return pattern;
    },

    /**
     * 获取单张鬼牌的牛牛
     * @param ghostArray
     * @param niuResult
     * @returns {*}
     */
    checkEachValue: function (ghostArray, niuResult) {

        // 可比较的手牌数
        var handCards = [];
        var pattern;

        this.getHandCards().getInitCards().forEach( function (card) {

            if (card != Poker.SpecPoint.JOKER_B
                && card != Poker.SpecPoint.JOKER_S) {
                handCards.push (card);
            }
        });

        // 获取选牌的
        var arrays = [];
        for (var index = 0; index < handCards.length - 1; ++index) {
            for (var index1 = index + 1; index1 < handCards.length; ++index1) {
                var selectedCards = [index, index1];
                var score = (NN.getPoint(handCards[index]) + NN.getPoint(handCards[index1]));
                arrays.push ({selectedCards: selectedCards, score: score});
            }
        }

        // 比较获取最大的index
        var niuScore = null;
        var niuIndex = 0;

        for (var index = 0; index < arrays.length; ++index) {
            var point = arrays[index].score % NN.BASE;

            // 存在牛牛直接退出
            if (point == 0) {
                niuIndex = index;
                niuScore = point;
                break;
            }

            if (niuScore && point > niuScore) {
                niuIndex = index;
                niuScore = point;
            }else if (!niuScore) {
                niuIndex = index;
                niuScore = point;
            }
        }

        // 根据最大分数获取最大牛分数
        // 并获取选牌
        var niuPoint = 0;
        var array = arrays[niuIndex].selectedCards;
        for (var index = 0; index < handCards.length; ++index) {

            if (array.indexOf(index) == -1) {
                niuPoint += NN.getPoint (handCards[index]);
                this._selectedCards.push (handCards[index]);
            }
        }

        var result = [];
        var ghostPoint = (10 - niuPoint % NN.BASE);
        if (niuScore % NN.BASE == 0) {
            pattern = Const.Pattern.niuniu;
        }else {
            pattern = Const.Pattern.wuNiu + niuScore;
        }

        if (ghostArray.length == 1) {
            result.push ({card: ghostArray[0], value: Poker.getValue (2, ghostPoint)});
            this._selectedCards.push (ghostArray[0]);
        }else {
            pattern = Const.Pattern.niuniu;

            var sumValue = this.getSumCard();
            var otherValue = (10 - (sumValue + ghostPoint) % NN.BASE);

            if (ghostPoint > sumValue) {
                result.push ({card: Poker.SpecPoint.JOKER_B, value: Poker.getValue (2, ghostPoint)});
                result.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, sumValue)});
                this._selectedCards.push (Poker.SpecPoint.JOKER_B);
            }else {
                result.push ({card: Poker.SpecPoint.JOKER_B, value: Poker.getValue (2, otherValue)});
                result.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, ghostPoint)});
                this._selectedCards.push (Poker.SpecPoint.JOKER_S);
            }
        }
        
        niuResult[pattern] = result;

        return pattern;
    },

    /**
     * 检查是否是五花牛
     * @param ghostArray
     * @param patternNiu
     * @returns {*}
     */
    checkWuHuaNiu : function (ghostArray, patternNiu) {

        // 获取花牌数量
        var colorNum = this.getColorNum();
        var pattern;

        if (colorNum + ghostArray.length == this.getInitHandCardNeedNum()) {
            pattern = Const.Pattern.wuHuaNiu;

            // 根据鬼牌数量创建听牌序列
            var niuResult = [];

            // 将鬼牌的替换值也获取
            // 多个鬼牌赋值
            for (var index = 0; index < ghostArray.length; ++index) {
                niuResult.push ({card: ghostArray[index], value: Poker.getValue(2,13)});
            }

            patternNiu[pattern] = niuResult;
        }

        return pattern;
    },

    /**
     * 检测五小牛
     * @param ghostArray
     * @param patternNiu
     * @returns {*}
     */
    checkWuXiaoNiu : function (ghostArray, patternNiu) {

        // 获取五小牛的数据
        var pattern;
        var sumValue = this.getSumCard();
        var costValue = (Const.defaultConst.wuXiaoNiuValue - sumValue);

        // 获取小于5的数量
        var isJudge = true;
        var handCards = clone (this._handCards.getInitCards());
        for (var index = 0; index < handCards.length; ++index) {
            if (Poker.getPoint (handCards[index]) >= 5) {
                isJudge = false;
                break;
            }
        }

        if (isJudge && costValue > ghostArray.length * 1) {
            pattern = Const.Pattern.wuXiaoNiu;
            var niuResult = [];

            // 获取鬼牌可选取的最大值
            if (ghostArray.length > 1) {
                niuResult.push ({card: Poker.SpecPoint.JOKER_B, value: costValue - 1});
                niuResult.push ({card: Poker.SpecPoint.JOKER_S, value: 1});
            } else if (ghostArray.length == 1) {
                niuResult.push ({card: ghostArray[0], value: costValue});
            }

            patternNiu[pattern] = niuResult;
        }

        return pattern;
    },

    /**
     * 检测坎斗
     * @param ghostArray
     * @param patternNiu
     * @returns {*}
     */
    checkKanDou: function (ghostArray, patternNiu) {

        // 检测坎斗
        var result = [];
        var handCards = clone (this.getHandCards().getInitCards());
        var sameArray = {};
        var maxPoint = 0;
        var maxArray = [];
        var pattern = null;

        // 获取炸弹牛组成的数列
        handCards.forEach(function (card) {
            if (card && card != Poker.SpecPoint.JOKER_B
                && card != Poker.SpecPoint.JOKER_S) {

                // 获取炸弹牛数组
                if(sameArray[Poker.getPoint(card)]){
                    sameArray[Poker.getPoint(card)].num += 1;
                    sameArray[Poker.getPoint(card)].cards.push(card);
                }else {
                    sameArray[Poker.getPoint(card)] =  {
                        num: 0,
                        cards: []
                    };
                    sameArray[Poker.getPoint(card)].num = 1;
                    sameArray[Poker.getPoint(card)].cards.push({card: card, value: card});
                }
            }
        });

        ExObject.each(sameArray, function (c, n) {
            if (n && n.num + ghostArray.length >= 3) {
                if (Poker.getPoint (n.cards[0].value) > maxPoint) {
                    maxPoint = Poker.getPoint (n.cards[0].value);
                    maxArray = n.cards;
                }
            }
        });

        if (maxArray.length > 0) {
            this._calcKanCards = maxArray;

            if (maxArray.length + ghostArray.length == 3) {
                ghostArray.forEach(function (ghost) {
                    result.push ({card: ghost, value: Poker.getValue (2, maxPoint)});
                    this._calcKanCards.push ({card: ghost, value: Poker.getValue (2, maxPoint)});
                }.bind (this));
            }else if (maxArray.length == 3) {
                ghostArray.forEach(function (ghost) {
                    result.push ({card: ghost, value: ghost});
                }.bind (this));
            }else {
                if (ghostArray.length == 1) {
                    result.push ({card: ghostArray[0], value: Poker.getValue (2, maxPoint)});
                    this._calcKanCards.push ({card: ghostArray[0], value: Poker.getValue (2, maxPoint)});
                }else if (ghostArray.length == 2) {
                    result.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxPoint)});
                    result.push ({card: Poker.SpecPoint.JOKER_B, value: Poker.SpecPoint.JOKER_B});
                    this._calcKanCards.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxPoint)});
                }
            }

            pattern = Const.Pattern.kanDou;
            patternNiu[pattern] = result;
        }

        return pattern;
    },

    /**
     * 检测顺斗
     * @param ghostArray
     * @returns {*}
     */
    checkShunDou: function (ghostArray, patternNiu) {

        // 需要将牌中除了鬼牌之外的牌拿出来
        var handCards = clone (this.getHandCards().getInitCards());
        var newArray = [];
        var pattern = null;
        var result = null;
        var maxArray = null;
        var indexContent = [];

        handCards.forEach (function (card) {
            if (card != Poker.SpecPoint.JOKER_B
                && card != Poker.SpecPoint.JOKER_S) {
                var point = Poker.getPoint(card);
                point = point == 14 ? 1 : point;

                if (indexContent.indexOf (point) == -1) {
                    indexContent.push (point);
                    newArray.push ({card: card, point: point});
                    console.log ("获取手牌中的点数: " + point);
                }
            }
        });

        newArray.sort (function (a, b) {
            return a.point - b.point;
        });

        // 获取有三张的顺子
        var array = this.getShunZiArray(newArray);
        var oneLaiArray = this.getShunZiOneGhost(newArray);
        var singleArray = this.getShunZiTwoGhost(newArray);

        console.log ("获取顺子的长度: " + array);
        console.log ("获取两个顺子的长度:" + oneLaiArray.length);
        console.log ("获取鬼牌的长度:" + ghostArray.length);

        // 本身能够成顺子的情况下, 当前的鬼牌直接判断为最大的
        if (array.length >= 1) {
            maxArray = this.getMaxArray (array);
            result = [];

            ghostArray.forEach(function (array) {
                result.push ({card: array, value: array});
            });
        } else if (ghostArray.length >= 1 && oneLaiArray.length >= 1) {
            // 有鬼牌的情况下
            maxArray = this.getMaxArrayOneGhost(oneLaiArray) ;
            result = [];

            if (ghostArray.length == 1) {
                if (maxArray.way == "lSide") {
                    this._calShunNiuCards.push ({card: ghostArray[0], value: Poker.getValue (2, maxArray.card2)});
                    result.push ({card: ghostArray[0], value: Poker.getValue (2, maxArray.left1)});
                }else if (maxArray.way == "rSide") {
                    this._calShunNiuCards.push ({card: ghostArray[0], value: Poker.getValue (2, maxArray.left1)});
                    result.push ({card: ghostArray[0], value: Poker.getValue (2, maxArray.left1)});
                }else if (maxArray.way == "inSide") {
                    this._calShunNiuCards.push ({card: ghostArray[0], value: Poker.getValue (2, maxArray.card2)});
                    result.push ({card: ghostArray[0], value: Poker.getValue (2, maxArray.left1)});
                }
            }else {
                if (maxArray.way == "lSide") {
                    this._calShunNiuCards.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.card2)});
                    result.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.left1)});
                }else if (maxArray.way == "rSide") {
                    this._calShunNiuCards.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.left1)});
                    result.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.left1)});
                }else if (maxArray.way == "inSide") {
                    this._calShunNiuCards.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.card2)});
                    result.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.left1)});
                }
                result.push ({card: Poker.SpecPoint.JOKER_B, value: Poker.SpecPoint.JOKER_B});
            }
        } else if (ghostArray.length == 2) {
            maxArray = this.getMaxArrayTwoGhost(singleArray);
            result = [];

            this._calShunNiuCards.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.left2)});

            result.push ({card: Poker.SpecPoint.JOKER_B, value: Poker.getValue (2, maxArray.left2)});
            result.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, maxArray.left1)});
        }

        if (maxArray) {
            pattern = Const.Pattern.shunDou;
            patternNiu[pattern] = result;
        }

        return pattern;
    },

    // /**
    //  * 获取坎顺斗中最大的鬼牌牌型
    //  * @param ghostArray
    //  * @param kanResult
    //  * @param shunResult
    //  * @param patternNiu
    //  */
    // getMaxKanShunDou: function (ghostArray, kanResult, shunResult, patternNiu) {

    //     var pattern;

    //     console.log ("同时比较坎顺斗的大小");

    //     var kanMax = this.getMaxCard (kanResult["ghost"]);
    //     var shunMax = this.getMaxCard (shunResult["ghost"]);

    //     pattern = Const.Pattern.kanShunDou;

    //     // 比较两者大小
    //     if (this.cardLT (kanMax, shunMax)) {
    //         patternNiu[pattern] = kanResult["ghost"];
    //         this._calShunNiuCards = [];
    //     }else {
    //         patternNiu[pattern] = shunResult["ghost"];
    //         this._calcKanCards = [];
    //     }

    //     return pattern;
    // },

    // /**
    //  * 检测坎顺斗
    //  * @param ghostArray
    //  * @param patternNiu
    //  * @returns {*}
    //  */
    // checkKanShunDou : function (ghostArray, patternNiu) {

    //     var pattern;

    //     // 判断当前的坎斗
    //     var kanResult = this.checkKanDou (ghostArray);
    //     console.log ("获取坎斗的结果: " + JSON.stringify(kanResult));

    //     // 判断当前的顺斗
    //     var shunResult = this.checkShunDou (ghostArray);
    //     console.log ("获取顺斗的结果: " + JSON.stringify(shunResult));

    //     // 获取当前两种牌型中最大的一种
    //     if (kanResult && shunResult) {
    //         console.log ("坎斗和顺斗都存在");
    //         pattern = this.getMaxKanShunDou (ghostArray, kanResult, shunResult, patternNiu);
    //     }else if (kanResult) {
    //         console.log ("坎斗存在");
    //         this._calShunNiuCards = [];
    //         pattern = Const.Pattern.kanShunDou;
    //         patternNiu[pattern] = kanResult["ghost"];
    //     } else if (shunResult) {
    //         console.log ("顺斗都存在");
    //         this._calcKanCards = [];
    //         pattern = Const.Pattern.kanShunDou;
    //         patternNiu[pattern] = shunResult["ghost"];
    //     }

    //     return pattern;
    // },

    // /**
    //  * 获取顺子和同花中比较大的一张
    //  * @sameColorResult
    //  * @shunZiResult
    //  * @patternNiu
    //  * @return pattern
    //  */
    // getMaxSSPattern: function (sameColorResult, shunZiResult, patternNiu) {

    //     var sameMax = this.getMaxCard (sameColorResult["ghost"]);
    //     var shunMax = this.getMaxCard (shunZiResult["ghost"]);

    //     pattern = Const.Pattern.tongHuaShunZi;

    //     // 比较两者大小
    //     if (this.cardLT (sameMax, shunMax)) {
    //         patternNiu[pattern] = sameColorResult["ghost"];
    //     }else {
    //         patternNiu[pattern] = shunZiResult["ghost"];
    //     }

    //     return pattern;
    // },
    
    /**
     * 是否是同花顺
     * @param isTongHua
     * @param isShunZi
     * @param patternNiu
     * @returns
     */
    checkTongHuaShunZi: function (isTongHua, isShunZi, patternNiu) {

        var pattern = null;
        var result = {};

        if (isTongHua && isShunZi) {

            // 获取当前牌型的花色
            var handcards = clone (this.getHandCards().getInitCards());
            var handColor = Poker.getColor(handcards[0]);

            // 获取顺子中的结果
            var shunResult = clone(patternNiu[Const.Pattern.shunZi]);
            shunResult.forEach (function (result) {
                var oldValue = clone(result.value);
                var point = Poker.getPoint (value);
                var value = Poker.getValue (handColor, point);
                result.value = value;
            });

            pattern = Const.Pattern.tongHuaShun;
            patternNiu[pattern] = shunResult;
        }

        // // 同花结果
        // var sameColorResult = this.checkSameColor (ghostArray);
        // console.log ("检测同花结果: " + JSON.stringify(sameColorResult));

        // // 顺子结果
        // var shunZiResult = this.checkAllShunZi (ghostArray);
        // console.log ("检测顺子结果: " + JSON.stringify(shunZiResult));

        // if (sameColorResult["sameColor"] && shunZiResult["shunZi"]) {
        //     pattern = this.getMaxSSPattern (sameColorResult, shunZiResult, patternNiu);
        // }else if (sameColorResult["sameColor"]) {
        //     pattern = Const.Pattern.tongHuaShunZi;
        //     patternNiu[pattern] = sameColorResult;
        // }else if (shunZiResult["shunZi"]) {
        //     pattern = Const.Pattern.tongHuaShunZi;
        //     patternNiu[pattern] = shunZiResult;
        // }

        return pattern;
    },

    /**
     * 检测同花
     * @param ghostArray
     * @param patternNiu
     * @returns {*}
     */
    checkSameColor : function (ghostArray, patternNiu) {

        var niuResult = null;
        var pattern = null;

        // 获取当前牌型中的花色
        if (this.isSameColor()) {
            console.log ("当前是同花");
            niuResult = [];

            // 获取花色
            var handCards = clone (this.getHandCards().getInitCards());
            var color = Poker.getColor (handCards[0]);

            for (var index = 0; index < ghostArray.length; ++index) {
                niuResult.push ({card: ghostArray[index], value: Poker.getValue (color, 13)});
            }

            pattern = Const.Pattern.tongHua;
            patternNiu[pattern] = niuResult;
        }

        console.log ("打印当前的牌型: " + pattern);

        return pattern;
    },

    /**
     * 检查顺子牌型
     * @param ghostArray 鬼牌
     * @param patternNiu 结算鬼牌的牌型
     * @param color      对选出的鬼牌的要求的花色
     * @returns pattern
     */
    checkAllShunZi : function (ghostArray, patternNiu, color) {

        var niuResult = [];
        var pattern = null;
        var judgeHandCards = this.getHandCards().getInitCards();
        var isbreak = false;
        var isHasA = false;

        // 获取顺序
        var handcards = [];
        var handPoint = [];
        for (var index = 0; index < judgeHandCards.length; ++index) {

            if (judgeHandCards[index] != Poker.SpecPoint.JOKER_B
                && judgeHandCards[index] != Poker.SpecPoint.JOKER_S) {
                var point = Poker.getPoint (judgeHandCards[index]);
                // 时候有A
                if (point == 1) {
                    isHasA = true;
                }

                if (handPoint.indexOf (point) != -1) {
                    isbreak = true;
                    break;
                }else {
                    handPoint.push (point);
                    handcards.push (judgeHandCards[index]);
                }
            }
        }

        if (isbreak) {
            return pattern;
        }

        // 进行排序
        handcards.sort (function (a, b) {
            return Poker.getPoint (a) - Poker.getPoint (b);
        });

        // 获取初始的值， 最终的值
        var initPoint = clone(Poker.getPoint(handcards[0]));
        var endPoint = clone(Poker.getPoint (handcards[handcards.length - 1]));
        var lastCard = initPoint;
        var initIndex = 0;

        // 定义空格数组
        var blockArr = [];

        // 特殊情况10JQKA
        if (isHasA) {
            // 如果最小的牌的点数是10，那么则将当前A变为14
            handcards.forEach (function(card) {
                if (Poker.getPoint(card) == 1) {
                    var color = Poker.getColor (card);
                    card = Poker.getValue (color, 14);
                }
            });
        }
        
        while (initPoint < endPoint) {
            // 获取到下一个值
            if (lastCard == initPoint) {
                ++initIndex;
                ++initPoint;
                
                if (initIndex > handcards.length) {
                    break;
                }else {
                    lastCard = Poker.getPoint(handcards[initIndex]);
                }

                continue;
            }
            ++initPoint;
            blockArr.push (initPoint);
        }

        if (blockArr.length == ghostArray.length) {

            var ghostColor = color || 2;

            // 如果存在HasA的情况下
            blockArr.forEach (function (card) {
                if (Poker.getPoint(card) == 14) {
                    var color = Poker.getColor (card);
                    card = Poker.getValue (color, 1);
                }
            });

            if (ghostArray.length == 1) {
                niuResult.push ({card: ghostArray[0], value: Poker.getValue(ghostColor, Poker.getPoint(blockArr[0]))});
            }else if (ghostArray.length == 2) {
                niuResult.push ({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue(ghostColor, Poker.getPoint(blockArr[0]))});
                niuResult.push ({card: Poker.SpecPoint.JOKER_B, value: Poker.getValue(ghostColor, Poker.getPoint(blockArr[1]))});
            }

            pattern = Const.Pattern.shunZi;
            patternNiu[pattern] = niuResult;
        }

        return pattern;
    },

    /**
     * 检查当前是否是炸弹牛
     * @param ghostArray
     * @param patternNiu
     * @returns
     */
    checkBoomNiu : function (ghostArray, patternNiu) {

        var pattern;

        // 获取手牌中的张数
        var handCards = this.getHandCards().getInitCards();
        var sameArray = {};
        var isBoom = false;
        var maxCard = 0;
        var maxScore = 0;

        // 获取炸弹牛组成的数列
        handCards.forEach(function (card) {
            if (card && card != Poker.SpecPoint.JOKER_B
                && card != Poker.SpecPoint.JOKER_S) {
                // 获取炸弹牛数组
                if(sameArray[Poker.getPoint(card)]){
                    sameArray[Poker.getPoint(card)].num += 1;
                    sameArray[Poker.getPoint(card)].cards.push(card);
                }else {
                    sameArray[Poker.getPoint(card)] =  {
                        num: 0,
                        cards: []
                    };
                    sameArray[Poker.getPoint(card)].num = 1;
                    sameArray[Poker.getPoint(card)].cards.push({card: card, value: card});
                }
            }
        });

        // 检测当前时候存在炸弹牛
        ExObject.eachKeyNum(sameArray, function(c, n){
            if(n.num + ghostArray.length >= 4){
                isBoom = true;
                maxScore = Poker.getPoint(n.cards[0].value);
                this._calBoomNiuCards = n.cards;
            }
        }.bind(this));

        if (isBoom) {
            pattern = Const.Pattern.boomNiu;

            var niuResult = [];
            var point = Poker.getPoint (this._calBoomNiuCards[0].value);

            if (handCards[maxCard] == 4 && ghostArray.length == 1) {
                niuResult.push ({card: ghostArray[0], value: Poker.getValue (2, 13)});
            }else if (handCards[maxCard] + ghostArray.length == 4) {
                this._calBoomNiuCards.push(Poker.getValue (2, point));
                ghostArray.forEach(function (array) {
                    niuResult.push ({card: array, value: Poker.getValue (2, point)});
                });
            }else if (handCards[maxCard] == 3 && ghostArray.length == 2) {
                this._calBoomNiuCards.push({card: Poker.SpecPoint.JOKER_S, value: Poker.getValue (2, point)});
                ghostArray.forEach(function (array) {
                    if (array == Poker.SpecPoint.JOKER_B) {
                        niuResult.push ({card: array, value: Poker.SpecPoint.JOKER_B});
                    }else {
                        niuResult.push ({card: array, value: Poker.getValue (2, point)});
                    }
                });
            }

            patternNiu[pattern] = niuResult;
        }

        return pattern;
    },

    /**
     * 检测五张牌里面的牛牌组
     * @returns {{}}
     */
    checkFiveNiu : function () {

        var niuScore;
        var len = 5;
        var cardsArr = this.getHandCards().getInitCards ();

        for (var c1 = 0; c1 < len - 2; ++c1) {
            if (cardsArr[c1] == Poker.SpecPoint.JOKER_B
                || cardsArr[c1] == Poker.SpecPoint.JOKER_S) {
                continue;
            }

            for (var c2 = c1 + 1; c2 < len - 1; ++c2) {
                if (cardsArr[c2] == Poker.SpecPoint.JOKER_B
                    || cardsArr[c2] == Poker.SpecPoint.JOKER_S) {
                    continue;
                }

                for (var c3 = c2 + 1; c3 < len; ++c3) {
                    if (cardsArr[c3] == Poker.SpecPoint.JOKER_B
                        || cardsArr[c3] == Poker.SpecPoint.JOKER_S) {
                        continue;
                    }

                    var point = NN.getPoint(cardsArr[c1]) + NN.getPoint(cardsArr[c2]) + NN.getPoint(cardsArr[c3]);
                    if (point % NN.BASE == 0) {
                        niuScore = point;

                        this._selectedCards = [cardsArr[c1], cardsArr[c2], cardsArr[c3]];
                        return point;
                    }
                }
            }
        }

        return niuScore;
    },

    /**
     * 对选入的牌进行判断牛分数
     * @param cards
     * @returns {*}
     */
    checkSelected : function (cards) {
        var niuScore;

        var point = 0;
        for (var index = 0; index < cards.length; ++index) {
            point += NN.getPoint(cards[index])
        }

        if (point % NN.BASE == 0) {
            niuScore = point;
        }

        this._selectedCards = cards;
        return niuScore;
    },

    /**
     * 检测牌型
     */
    checkPattern : function () {

        // 获取当前玩家的牌型列表
        var patternResult = [Const.Pattern.wuNiu];
        var room = this.getRoom();
        // || {
        //     getOption: function(value) {
        //         if (value == "kanShunDou") {
        //             return true;
        //         }
        //     },

        //     getPatternScore: function (pattern) {
        //         // if (this.getOption ("fanRule")
        //         //     && pattern >= Const.SpecRule["bottom"]
        //         //     && pattern <= Const.SpecRule["top"]) {
        //         //     return Const.SpecRule[pattern];
        //         // }else {
        //             return Const.PatternScore[pattern];
        //         // }
        //     }
        // };

        // 获取鬼牌
        var ghostArray = [];
        if (room.getOption("ghost")) {
            ghostArray = this.getGhostArray();
            console.log ("鬼牌的数量：" + ghostArray);
        }

        var resultNiu = {};

        var pattern = this.checkNiu (ghostArray, resultNiu);
        console.log ("检测牛之后的牌型:" + pattern);
        if (pattern) {
            patternResult.push (pattern);
        }

        // 获取坎顺斗
        if (room.getOption("kanShunDou")) {
            pattern = this.checkKanDou (ghostArray, resultNiu);
            console.log ("检测坎斗之后的牌型:" + pattern);
            if (pattern) {
                patternResult.push (pattern);
            }

            pattern = this.checkShunDou(ghostArray, resultNiu);
            console.log ("检测顺斗之后的牌型:" + pattern);
            if (pattern) {
                patternResult.push (pattern);
            }
        }

        // 获取炸弹牛
        if (room.getOption("boomNiu")) {
            pattern = this.checkBoomNiu(ghostArray, resultNiu);
            console.log("检测炸弹牛之后的牌型:" + pattern);
            if (pattern) {
                patternResult.push(pattern);
            }
        }

        // 获取同花顺子
        if (room.getOption("tongHuaShunZi")) {
            var isTongHua = false;
            var isShunZi = false;

            pattern = this.checkSameColor(ghostArray, resultNiu);
            console.log ("检测同花:" + pattern);
            if (pattern) {
                isTongHua = true;
                patternResult.push (pattern);
            }

            pattern = this.checkAllShunZi(ghostArray, resultNiu);
            console.log ("检测顺子:" + pattern);
            if (pattern) {
                isShunZi = true;
                patternResult.push (pattern);
            }

            pattern = this.checkTongHuaShunZi(isTongHua, isShunZi, resultNiu);
            console.log("检测同花顺子之后的牌型:" + pattern);
            if (pattern) {
                patternResult.push(pattern);
            }
        }

        // 获取五花牛
        if (room.getOption("wuHuaNiu")) {
            pattern = this.checkWuHuaNiu(ghostArray, resultNiu);
            console.log("检测五花牛之后的牌型:" + pattern);
            if (pattern) {
                patternResult.push(pattern);
            }
        }

        // 获取五小牛
        if (room.getOption("wuXiaoNiu")) {
            pattern = this.checkWuXiaoNiu(ghostArray, resultNiu);
            console.log("检测五小牛之后的牌型:" + pattern);
            if (pattern) {
                patternResult.push(pattern);
            }
        }

        var result = this.getMaxPattern (patternResult, resultNiu);
        var patternScore = room.getPatternScore(result.Pattern);
        console.log ("最终检测之后的牌型:" + result.Pattern);
        console.log ("获取最终获得的牌型分数:" + patternScore);

        // 设置为玩家的结算牌型
        this.setRoundPattern(result.Pattern, patternScore);
    },

    onCurRoundFinished: function () {
        this._super();

        this._handCards.reset();

        this._robDealer = -1;
        this._selectedCards = [];
        this._ante = 0;
        this._tuiZu = [];
        this._playCards = false;
        this._stat.roundPattern = 0;
        this._stat.roundPatternScore = 0;
        this._calcKanCards = [];
        this._calBoomNiuCards = [];
        this._ghostResultArray = [];
        this._lookCards = false;
        this._giveUp = false;
        this._compareIndexArr = [];
    },

    /******************************************************************
     * 私有功能函数
     ******************************************************************/

    /**
     * 发送并且初始化当前玩家的手牌
     * @param cardArr
     */
    InitHandCards: function (cardArr) {
        this._handCards.init(cardArr);

        var cards = this.getHandCards().getInitCards();

        this.send ("onPlayerCard", {
           playerIndex : this.getIndex(),
            cardLength : cards.length,
                 cards : cards
        });
    },

    /**
     * 获取到的鬼牌结果数组
     * @param ghostArray
     */
    getMaxCard: function (ghostArray) {

        var ghostResult = {};
        var handCards = [];

        // 优先获取是否有鬼牌
        if (ghostArray && ghostArray.length >= 1) {

            console.log ("有鬼牌检测");

            ghostArray.forEach (function (ghost) {
                console.log ("获取鬼牌数列: key=" + ghost.card + " value=" + ghost.value);
                ghostResult[ghost.card] = ghost.value;
            });

            this.getHandCards().getInitCards().forEach (function (key) {
                if (key == Poker.SpecPoint.JOKER_B
                    || key == Poker.SpecPoint.JOKER_S) {
                    console.log ("有鬼牌" + " 鬼牌结果: " + ghostResult[key]);
                    handCards.push({card: key, value: ghostResult[key]});
                }else {
                    handCards.push({card: key, value: key});
                }
            });

            return this._getMaxCard (handCards);
        }else {

            console.log ("无鬼牌检测");

            this.getHandCards().getInitCards().forEach (function (key) {
                handCards.push({card: key, value: key});
            });

            return this._getMaxCard (handCards);
        }
    },

    /**
     * 进行获取最大值
     * @param handCards
     * @returns {*}
     * @private
     */
    _getMaxCard: function(handCards) {
        var maxScore = 0;
        var maxArray;
        var allCardsArr = [];

        if (handCards && handCards.length >= 1) {
            allCardsArr = handCards;
        }

        for (var index = 0; index < allCardsArr.length; ++index) {
            var card = allCardsArr[index];

            console.log ("当前的牌: " + JSON.stringify(card));
            if (maxArray) {
                console.log ("获取当前的牌值：" + card.value + " 最大的牌值:" + maxArray.value);
            }

            if (this.cardLT(card, maxArray)) {
                console.log ("当前比牌为赢");
                maxScore = card.value;
                maxArray = card;
            }
        }

        return maxArray;
    },

    /**
     * 进行鬼牌比较
     * @param cardArray
     * @param maxCardArray
     */
    cardLT: function (cardArray, maxCardArray) {

        if (!cardArray) {
            return false;
        } else if (!maxCardArray) {
            return true;
        }

        // 比较一次值
        if (cardArray.value == Poker.SpecPoint.JOKER_B) {
            return true;
        }else if (maxCardArray.value == Poker.SpecPoint.JOKER_B) {
            return false;
        }else if (cardArray.value == Poker.SpecPoint.JOKER_B
                    && maxCardArray.value == Poker.SpecPoint.JOKER_S) {
            return true;
        }else if (maxCardArray.value == Poker.SpecPoint.JOKER_S
                    && cardArray.value == Poker.SpecPoint.JOKER_B) {
            return false;
        }else if (cardArray.value == Poker.SpecPoint.JOKER_S) {
            return true;
        }else if (maxCardArray.value == Poker.SpecPoint.JOKER_S) {
            return false;
        }

        var point1 = Poker.getPoint(cardArray.value);
        var point2 = Poker.getPoint(maxCardArray.value);
        console.log ("获取第一个牌的值: " + cardArray.value);
        console.log ("获取第二个牌的值: " + maxCardArray.value);

        if (point1 == point2) {
            var color1 = Poker.getColor(cardArray.value);
            var color2 = Poker.getColor(maxCardArray.value);

            console.log ("获取第一个牌的花色: " + color1);
            console.log ("获取第二个牌的花色: " + color2);

            if (NN.ColorCompareValue[color1] == NN.ColorCompareValue[color2]) {
                if (cardArray.card == Poker.SpecPoint.JOKER_B) {
                    return true;
                }else if (maxCardArray.card == Poker.SpecPoint.JOKER_B) {
                    return false;
                }else if (cardArray.card == Poker.SpecPoint.JOKER_B
                            && maxCardArray.card == Poker.SpecPoint.JOKER_S) {
                    return true;
                }else if (maxCardArray.card == Poker.SpecPoint.JOKER_S
                            && cardArray.card == Poker.SpecPoint.JOKER_B) {
                    return false;
                }else if (cardArray.card == Poker.SpecPoint.JOKER_S) {
                    return true;
                }else if (maxCardArray.card == Poker.SpecPoint.JOKER_S) {
                    return false;
                }
            }

            return NN.ColorCompareValue[color1] > NN.ColorCompareValue[color2];
        } else {
            return point1 > point2;
        }
    },

    compareEach: function(dealerPlayer){

        var player = this;
        var firResult = {Pattern: player.getRoundPattern(), maxArray: []};
        var sedResult = {Pattern: dealerPlayer.getRoundPattern(), maxArray: []};

        // 获取当前玩家的最大牌
        if (firResult.Pattern == Const.Pattern.boomNiu
            && sedResult.Pattern == Const.Pattern.boomNiu) {
            var compareResult = this.compareKanBoom (firResult, player.getBoomCards(), sedResult, dealerPlayer.getBoomCards());
            if (compareResult != -1) {
                return compareResult == 1;
            }
        }

        //if (firResult.Pattern == Const.Pattern.kanShunDou
        //    && sedResult.Pattern == Const.Pattern.kanShunDou) {
        //    var compareResult = this.compareKanBoom (firResult, player.getKanShunCards(), sedResult, dealerPlayer.getKanShunCards());
        //
        //    if (compareResult != -1) {
        //        return compareResult == 1;
        //    }
        //}

        // 获取对另外一个比牌的玩家的最大牌
        firResult.maxArray = player.getMaxCard(player.getGhostPlaceArray());
        console.log ("获得发起比较玩家的最大牌组: " + JSON.stringify(firResult));
        sedResult.maxArray = dealerPlayer.getMaxCard(dealerPlayer.getGhostPlaceArray());
        console.log ("获得被比较玩家的最大牌组: " + JSON.stringify(sedResult));

        return player.compareEachResult (firResult, sedResult);
    },

    /**
     * 比较两个玩家的牌型
     * @param firResult
     * @param sedResult
     * @returns {boolean}
     */
    compareEachResult: function (firResult, sedResult) {

        if (!sedResult) {
            return true;
        } else if (!firResult) {
            return false;
        }

        var room = this.getRoom();
        // || {
        //     getOption: function(value) {
        //         if (value == "tongHuaShunZi") {
        //             return true;
        //         }
        //     },

        //     getPatternScore: function (pattern) {
        //         // if (this.getOption ("fanRule")
        //         //     && pattern >= Const.SpecRule["bottom"]
        //         //     && pattern <= Const.SpecRule["top"]) {
        //         //     return Const.SpecRule[pattern];
        //         // }else {
        //             return Const.PatternScore[pattern];
        //         // }
        //     }
        // };
        var result = false;
        var firScore = room.getPatternScore(firResult.Pattern);
        var sedScore = room.getPatternScore(sedResult.Pattern);

        console.log ("获取第一个的牌型分数: " + firScore);
        console.log ("获取第一个的牌型: " + firResult.Pattern);
        console.log ("获取第二个的牌型分数: " + sedScore);
        console.log ("获取第一个的牌型: " + sedResult.Pattern);

        // 之后可能有特殊情况的判断
        if (firScore > sedScore) {
            return true;
        }else if (firScore != 4) {
            if (firResult.Pattern > sedResult.Pattern) {
                return true;
            } else if (firResult.Pattern == sedResult.Pattern) {
                var maxCard = firResult.maxArray;
                var playerMaxCard = sedResult.maxArray;

                if (this.cardLT (maxCard, playerMaxCard)) {
                    return true;
                }
            }
        }else if (firScore == sedScore) {
            var maxCard = firResult.maxArray;
            var playerMaxCard = sedResult.maxArray;

            if (this.cardLT (maxCard, playerMaxCard)) {
                return true;
            }
        }

        return result;
    },

    /**
     * 比较坎和顺
     * @param firResult
     * @param firKanCards
     * @param sedResult
     * @param sedKanCards
     * @returns {number}
     */
    compareKanBoom: function (firResult, firKanCards, sedResult, sedKanCards) {

        console.log ("打印第一个玩家的坎顺值: " + JSON.stringify (firKanCards));
        console.log ("打印第二个玩家的坎顺值:" + JSON.stringify (sedKanCards));

        if (firKanCards.length < 1 || sedKanCards.length < 1) {
            return -1;
        }

        console.log ("同时比较坎顺斗");

        firResult.maxArray = this._getMaxCard(firKanCards);
        sedResult.maxArray = this._getMaxCard(sedKanCards);

        if (!firResult.maxArray) {
            return 0;
        } else if (!sedResult.maxArray) {
            return 1;
        }

        var point1 = NN.getPoint (firResult.maxArray.value);
        var point2 = NN.getPoint (sedResult.maxArray.value);

        // 比较对应的坎数, 如果相同, 则获取最大牌比较
        if (point1 == point2) {
            return -1;
        }

        return point1 > point2 ? 1 : 0;
    }
});